package com.msmall.community.cookbook.service.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.msmall.base.util.ConstantDB;
import com.msmall.community.cookbook.service.CookbookManager;
import com.msmall.community.user.model.UserSetting;
import com.msmall.community.user.service.UserManager;

public class CookbookManagerImpl implements CookbookManager{

	private static final Log log = LogFactory.getLog(CookbookManagerImpl.class);
	
	private UserManager userManager;

	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}
	/**
	 * 用户是否被授权推荐问答
	 */
	public boolean isAuthorizedCommend(Long userid){
		try{
			UserSetting setting = userManager.getSetting(userid, ConstantDB.USER_SETTING_KEY_COMMEND_COOKBOOK);
			if(setting == null)
				return false;
			if(ConstantDB.USER_SETTING_VALUE_COMMEND_COOKBOOK_TOP.equals(setting.getPropertyValue())){
				return true;
			}
		}catch(Exception e){
			log.debug(e);
		}
		return false;
	}
	/**
	 * 用户是否被授权删除问答/回复
	 */
	public boolean isAuthorizedRemove(Long userid){
		try{
			UserSetting setting = userManager.getSetting(userid, ConstantDB.USER_SETTING_KEY_REMOVE_COOKBOOK);
			if(setting == null)
				return false;
			if(ConstantDB.USER_SETTING_VALUE_REMOVE_COOKBOOK_TOP.equals(setting.getPropertyValue())){
				return true;
			}
		}catch(Exception e){
			log.debug(e);
		}
		return false;
	}
	/**
	 * 用户是否被授权创建问答/回复
	 */
	public boolean isAuthorizedCreate(Long userid){
		try{
			UserSetting setting = userManager.getSetting(userid, ConstantDB.USER_SETTING_KEY_CREATE_COOKBOOK);
			if(setting == null)
				return false;
			if(ConstantDB.USER_SETTING_VALUE_CREATE_COOKBOOK_TOP.equals(setting.getPropertyValue())){
				return true;
			}
		}catch(Exception e){
			log.debug(e);
		}
		return false;
	}
	
	/**
	 * 用户是否被授权更新问答/回复
	 */
	public boolean isAuthorizedUpdate(Long userid){
		try{
			UserSetting setting = userManager.getSetting(userid, ConstantDB.USER_SETTING_KEY_UPDATE_COOKBOOK);
			if(setting == null)
				return false;
			if(ConstantDB.USER_SETTING_VALUE_UPDATE_COOKBOOK_TOP.equals(setting.getPropertyValue())){
				return true;
			}
		}catch(Exception e){
			log.debug(e);
		}
		return false;
	}
}
